package com.yueyang.sojourn.server.common;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.IOException;
import java.lang.invoke.MethodHandles;

/**
 * ares-remoting  JsonUtils
 *
 * @author Guangshan
 * @date 2017/11/5 20:13
 * @since 0.0.1
 */
public abstract class JsonUtils {

    private static final Log logger = LogFactory.getLog(MethodHandles.lookup().lookupClass());

    private static final ObjectMapper jsonConverter = new ObjectMapper();

    public static <T> T parseObject(String json, Class<T> clazz) {
        try {
            return jsonConverter.readValue(json, clazz);
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
            return null;
        }

    }

}
